package com.danchuang.consumer.service;

import com.danchuang.consumer.config.RabbitConfig;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.GetResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.BatchMessageListener;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author haitao
 * @date 2021/9/2 3:23 下午
 */
@Service
@Slf4j
public class BasicGetReceiver implements BatchMessageListener {

    //批量接收处理
    @RabbitListener(queues = RabbitConfig.BASIC_QUEUE,containerFactory = "batchQueueRabbitListenerContainerFactory")
    @Override
    public void onMessageBatch(List<Message> messages) {
        log.info("batch.queue.consumer 收到{}条message", messages.size());
        if(messages.size()>0){
            log.info("第一条数据是: {}", new String(messages.get(0).getBody()));
        }
    }
}